package com.caseProcess.controller;

import com.caseProcess.entity.*;
import com.caseProcess.service.VCaseProcInfosService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ahuo
 * @version 1.0
 * @date 2020年11月15日 14点41分
 */
@RestController
@RequestMapping("/vProcInfo")
public class VCaseProcInfosController {
    @Resource
    VCaseProcInfosService vCaseProcInfosService;



    /**
     * 查询具体分派的所有处理过程
     * @param processId
     * @return
     */
    @CrossOrigin
    @RequestMapping("/selectByProcessId")
    public Result selectByProcessId(String processId){
        VCaseProcInfo vCaseProcInfo=new VCaseProcInfo();
        vCaseProcInfo.setProcessId(processId);
        List<VCaseProcInfo> vcase=vCaseProcInfosService.selectVCaseProcInfos(vCaseProcInfo);
        Result result = new Result();
        result.setCode(Result.RESULT_OK);
        result.setCount(vcase.size());
        result.setMsg("信息查询成功");
        result.setData(vcase);
        return result;
    }


    /**
     * 按条件查询待指派案件
     * @param caseId 案件编号
     * @param procLevel 督办等级
     * @param caseDescription 警情描述
     * @param startTime 选择的开始时间
     * @param endTime 选择的结束时间
     * 查询的是在以上两个时间范围内的相关分派时间的案件
     */
    @RequestMapping("/selectByStamentByDepartment")
    public Result selectByStamentByDepartment(String caseId, String procLevel, String caseDescription, String startTime, String endTime,long procTatus, HttpServletRequest request) {
        Result result=new Result();
        Object object=SessionController.getSession(request,"police");
        if(object==null){
            result.setCode(-500);
            result.setMsg("用户信息错误,请重新登陆");
            return result;
        }
        VUserInfo vUserInfo= (VUserInfo) object;
        List<VCaseProcInfo> list= new ArrayList<VCaseProcInfo>();
        VCaseProcInfo vCaseProcInfo=new VCaseProcInfo();
        vCaseProcInfo.setCaseId(caseId);
        vCaseProcInfo.setProcLevel(procLevel);
        vCaseProcInfo.setCaseDescription(caseDescription);
        vCaseProcInfo.setProcDepartmentId(vUserInfo.getDepartmentId());
        list=vCaseProcInfosService.selectByFactor(vCaseProcInfo,startTime,endTime,procTatus);
        if (list.size() >= 0){
            result.setCode(Result.RESULT_OK);
            result.setMsg("操作成功");
            result.setData(list);
            result.setCount(list.size());
        }else{
            result.setCode(Result.RESULT_ERROR);
            result.setMsg("操作失败");
        }
        return result;
    }
}
